<template>
	<view>

		<!-- 选项卡 -->
		<view class="recordTab_box">
			<view class="recordTab_con">
				<view :class="'recordTabItem '+(recordTabIndex==0?'active':'')" @click="tabClick(0)">
					<text>按工人</text>
				</view>
				<view :class="'recordTabItem '+(recordTabIndex==1?'active':'')" @click="tabClick(1)">
					<text>按工地</text>
				</view>
			</view>
		</view>

		<!-- 按工人 -->
		<template v-if="recordTabIndex==0">
			<view class="statsWrap_box">
				<!-- 默认工地统计 -->
				<view class="projectStats_con">
					<view class="statsList_con">
						<view class="statsItem">
							<view class="statsLabel">总工</view>
							<view class="statsMoney">
								{{memberTotal.num}}
								
								<text class="overHout" v-if="memberTotal.overtime_hour>0">+{{memberTotal.overtime_hour}}</text>
								<text class="overHout" v-if="memberTotal.overtime_hour>0">H</text>
							</view>
						</view>
						<view class="statsLine"></view>
						<view class="statsItem">
							<view class="statsLabel">总工资(元)</view>
							<view class="statsMoney">
								{{memberTotal.total_money}}
							</view>
						</view>
					</view>
					<view class="statsMoney_con">
						<image src="/static/moneyIcon.png" mode=""></image>
						<text>已支付(元)：{{memberTotal.yes_money}}，剩余工资(元)：{{memberTotal.no_money}}</text>
					</view>
				</view>
				
				
				<view class="tableOutBox">
					<view class="tableInBox">
						<view class="tableTr">
							<view class="tableTd ">工友姓名</view>
							<view class="tableTd tableTd30">总工</view>
							<view class="tableTd tableTd30">总工资</view>
							<view class="tableTd tableTd15">更多</view>
						</view>
						
						<view class="tableTr" v-for="(item,index) in memberList" 
									:key="index" @click="goPage('./statisticsWorker?user_id='+item.user_id)">
							<view class="tableTd ">{{item.name}}</view>
							<view class="tableTd tableTd30 color1"><text>{{item.num}}</text>{{item.work_class_type_str}} 
							<text v-if="item.overtime_hour>0">({{item.overtime_hour}}H)</text></view>
							<view class="tableTd tableTd30  color2">{{item.money}}</view>
							<view class="tableTd tableTd15"><u-icon name="arrow-right-double" color="#aaa" size="28"></u-icon></view>
						</view>
					</view>
				</view>
				
				

				<!-- <view class="recordList_box">
					<view class="recordList_con">
						<view class="recordItem"
							@click="goPage('./statisticsWorker?user_id='+item.user_id)"
							v-for="(item,index) in memberList" :key="index">
							<u-avatar :src="item.header_img" mode="square"></u-avatar>
							<view class="recordInfo">
								<view class="recordName">{{item.name}}</view>
							</view>
							<view class="recordWork">
								<view class="recordMoney">{{item.money}}</view>
								<view class="recordDay">
									<text>{{item.num}}</text>{{item.work_class_type_str}}
								</view>
							</view>
							<u-icon name="arrow-right" color="#999" size="32"></u-icon>
						</view>
					</view>
				</view> -->
			</view>
		</template>

		<!-- 按工地 -->
		<template v-if="recordTabIndex == 1">
			<view style="width: 100%; height: 30rpx;"></view>
			<view class="tableOutBox">
				<view class="tableInBox">
					<view class="tableTr">
						<view class="tableTd tableTd20">工地名称</view>
						<view class="tableTd tableTd35">合计</view>
						<view class="tableTd tableTd35">工资</view>
						<view class="tableTd tableTd10">表格</view>
					</view>
					
					<view class="tableTr tableTr2" v-for="(item,index) in projectList" 
								:key="index" >
						<view class="tableTd tableTd20" @click="goPage('./statisticsWorksite?project_id='+item.id)"><view class="kongItem"></view>{{item.name}}</view>
						<view class="tableTd tableTd2 tableTd35" @click="goPage('./statisticsWorksite?project_id='+item.id)">
							<view class="kongItem"></view>
							<view class="tableTdItem">
								总<text class="ziOne"></text>{{item.work_class_type_str}}:<text class="color1">{{item.total_num}}{{item.work_class_type_str}}</text>
							</view>
							<view class="tableTdItem" v-if="item.overtime_hour>0">
								加<text class="ziOne"></text>班:<text class="color1">{{item.overtime_hour}}H</text>
							</view>
							<view class="tableTdItem">
								总工资:<text class="color1">{{item.total_money}}</text>
							</view>
						</view>
						<view class="tableTd tableTd2 tableTd35" @click="goPage('./statisticsWorksite?project_id='+item.id)">
							<view class="kongItem"></view>
							<view class="tableTdItem">
								已支付:<text class="color2">{{item.out_money}}</text>
							</view>
							<view class="tableTdItem">
								剩余工资:<text class="color2">{{item.no_money}}</text>
							</view>
						</view>
						<view class="tableTd  tableTd3 tableTd10" @click="goPage('./excelExport?type=3&project_id='+item.id)">下载</view>
					</view>
				</view>
			</view>
			
			
			<!-- <view class="statsWrap_box">
				<view class="statsWrap_con">
					<view class="statsItem" v-for="(item,index) in projectList" :key="index"
						>
						<view class="statsUser_con">
							<view class="userAvatar">
								<image src="/static/projectIcon.png" mode=""></image>
							</view>
							<view class="userName">{{item.name}}</view>
							<view class="userDownload" @click="goPage('./excelExport?type=3&project_id='+item.id)">
								<image src="/static/download.png" mode=""></image>
								<text>工地汇总表</text>
							</view>
						</view>
						<view class="projectStats_con" @click="goPage('./statisticsWorksite?project_id='+item.id)">
							<view class="statsList_con">
								<view class="statsItem">
									<view class="statsLabel">总{{item.work_class_type_str}}</view>
									<view class="statsMoney">
										{{item.total_num}}
										<text v-if="item.overtime_hour>0">{{item.work_class_type_str}}</text>
										+{{item.overtime_hour}}
										<text v-if="item.overtime_hour>0">小时</text>
									</view>
								</view>
								<view class="statsLine"></view>
								<view class="statsItem">
									<view class="statsLabel">总工资(元)</view>
									<view class="statsMoney">
										{{item.total_money}}
									</view>
								</view>
							</view>
							<view class="statsMoney_con">
								<image src="/static/moneyIcon.png" mode=""></image>
								<text>已支付(元)：{{item.out_money}}，剩余工资(元)：{{item.no_money}}</text>
							</view>
						</view>
					</view>
				</view>
			</view> -->
		</template>
		
		<view style="width: 100%; height: 200rpx;">
			
		</view>
		<!-- 下载excel -->
		<view class="downloadExcel" v-if="recordTabIndex==0" 
			@click="goPage('./excelExport?type=1')">
			<image src="/static/img/excel.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 选项卡
				recordTabIndex: 0,

				// 按工人
				memberList: [],
				memberTotal: {
					total_money: '',
					no_money: '',
					yes_money: '',
					num: '',
				},

				// 按工地
				projectList: [],

				roleType: '',
			}
		},
		onLoad(e) {
			if (e.role) {
				this.roleType = e.role;
			}
		},
		onShow() {
			var _this = this;
			_this.getByMember();
			_this.getByProject();
		},
		methods: {
			// 选项卡切换
			tabClick(val) {
				this.recordTabIndex = val;
			},

			// 按工人
			getByMember() {
				var _this = this;
				_this.$u.get('/api/project.monthdata/dataByMember', {
					roleType: _this.roleType
				}).then(res => {
					uni.hideLoading();
					console.log("==按工人==");
					console.log(res);
					_this.memberList = res.data;
					_this.memberTotal = res.extend;
				}).catch(res => {
					console.log(res);
				})
			},

			// 按工地
			getByProject() {
				var _this = this;
				_this.$u.get('/api/project.monthdata/dataByProject', {

				}).then(res => {
					uni.hideLoading();
					console.log("==按工地==");
					console.log(res);
					_this.projectList = res.data;
				}).catch(res => {
					console.log(res);
				})
			},

			// 页面跳转
			goPage(url) {
				console.log(url)
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style scoped lang="scss">
	.statsWrap_box {
		padding: 0 30rpx
	}
	
	.statsItem{
		padding-top: 30rpx;
	}
	
	.statsUser_con {
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.userAvatar {
		width: 64rpx;
		height: 64rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.userAvatar image {
		width: 100%;
		height: 100%;
	}

	.userName {
		flex: 2;
		font-size: 28rpx;
		font-weight: bold;
		color: $uni-color;
		margin: 0 20rpx;
	}

	.userDownload {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.userDownload image {
		width: 28rpx;
		height: 28rpx;
	}

	.userDownload text {
		font-size: 28rpx;
		font-weight: bold;
		color: $uni-color-active;
		margin-left: 10rpx;
	}

	.projectStats_con {
		padding: 30rpx 0;
	}

	.statsList_con {
		height: 200rpx;
		background: #f0f6ff;
		border: 2rpx solid #cce0ff;
		border-radius: 10rpx 10rpx 0 0;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.projectStats_con .statsItem {
		flex: 1;
		text-align: center;
	}

	.projectStats_con .statsLabel {
		font-size: 28rpx;
		color: #8B8A90;
	}

	.projectStats_con .statsMoney {
		font-size: 54rpx;
		font-weight: bold;
		color: #000;
		margin-top: 20rpx;
	}

	.projectStats_con .statsMoney text {
		font-size: 28rpx;
	}

	.projectStats_con .statsLine {
		width: 2rpx;
		height: 60rpx;
		background-color: #CCE0FF;
	}

	.projectStats_con .statsMoney_con {
		height: 90rpx;
		padding: 0 30rpx;
		background: #327fe8;
		border-radius: 0 0 10rpx 10rpx;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		align-items: center;
	}

	.projectStats_con .statsMoney_con image {
		width: 30rpx;
		height: 30rpx;
	}

	.projectStats_con .statsMoney_con text {
		font-size: 28rpx;
		color: #fff;
		margin-left: 20rpx;
	}

	// 按工人
	.recordList_box {
		background: #f0f6ff;
		border-radius: 30rpx;
		overflow: hidden;
	}

	.recordList_con {
		padding: 0 30rpx;
		overflow: hidden;
	}

	.recordItem {
		padding: 30rpx 0;
		border-bottom: 1rpx solid #eee;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.recordInfo {
		flex: 2;
		margin: 0 20rpx;
	}

	.recordName {
		font-size: 32rpx;
		font-weight: bold;
		color: #000000;
	}

	.recordSalary {
		color: #999;
		margin-top: 10rpx;
	}

	.recordWork {
		text-align: center;
		overflow: hidden;
		margin-right: 10rpx;
	}

	.recordMoney {
		font-size: 32rpx;
		font-weight: bold;
		color: #000000;
		overflow: hidden;
	}

	.recordDay {
		font-size: 24rpx;
		color: $uni-color-primary;
		overflow: hidden;
		margin-top: 10rpx;
	}
	
	
	
	
	//表格
	.tableOutBox{
		background-color: #dae1e8;
		border-left: 2rpx solid #e2e2e2;
		border-top: 2rpx solid #e2e2e2;
		box-sizing: border-box;
		width: 690rpx;
		margin: 0rpx auto;
		border-radius: 10rpx;
		overflow: hidden;
	}
	
	.tableInBox{
		background-color: #fff;
		border-radius: 10rpx;
	}
	.tableTr{
		height: 90rpx;
		line-height: 90rpx;
		overflow: hidden;
		background-color: #f7fbfe;
		border-bottom: 2rpx solid #e2e2e2;
	}
	.tableTr2{
		min-height: 170rpx;
		line-height: 50rpx;
		text-align: left;
		font-size: 28rpx;
		font-weight: 400;
		box-sizing: border-box;
	}
	.tableTr:nth-child(2n){
		background-color: #ffff;
	}
	.tableTd{
		width: 25%;
		height: 100%;
		text-align: center;
		padding-left: 10rpx;
		float: left;
		font-size: 26rpx;
		font-weight: bold;
		border-right: 2rpx solid #e2e2e2;
	}
	.tableTd2{
		text-align: left;
		padding-left: 10rpx;
		font-weight: 400;
		font-size: 26rpx;
		color: #333;
	}
	.tableTd3{
		text-align: center;
		line-height: 170rpx;
		color: #327fe8;
		font-size: 26rpx;
		padding-left: 0rpx;
	}
	.color1{
		color: #ff6600;
	}
	.color2{
		color: #35c700;
	}
	
	.tableTd10{
		width: 10%;
	}
	.tableTd15{
		width: 15%;
	}
	.tableTd20{
		width: 20%;
	}
	.tableTd30{
		width: 30%;
	}
	.tableTd35{
		width: 35%;
	}
	.kongItem{
		width: 100%;
		height: 10rpx;
	}
	.ziOne{
		padding-left: 28rpx;
	}
	
	// 下载excel
	.downloadExcel {
		position: fixed;
		right: 30rpx;
		bottom: 30rpx;
	}
	
	.downloadExcel image {
		width: 100rpx;
		height: 100rpx;
	}
	
	
	.overHout{
		font-size: 28rpx;
		color: #f00;
	}
</style>
